/**
 * 
 */
package com.ydy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydy.annotation.AdminToken;
import com.ydy.annotation.CheckFormRepeat;
import com.ydy.annotation.CtrlParam;
import com.ydy.model.Brand;
import com.ydy.service.brand.BrandService;
import com.ydy.utils.StringUtils;
import com.ydy.vo.other.BaseVo;
import com.ydy.vo.other.PageVo;

/**
 * @author xuzhaojie
 *
 *         2019年1月18日 上午9:17:29
 */
@Controller
@RequestMapping(value = "brand", name = "品牌模块")
public class BrandController {

	@Autowired
	private BrandService brandService;

	@GetMapping(value = "list", name = "展示品牌列表")
	@ResponseBody
	public ResponseEntity<PageVo<Brand>> list(Brand brand, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(brand);
		PageVo<Brand> vo = brandService.list(brand, page, size);
		return ResponseEntity.ok(vo);
	}

	@AdminToken
	@GetMapping(value = "select", name = "管理员筛选品牌列表")
	@ResponseBody
	public ResponseEntity<PageVo<Brand>> select(Brand brand, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(brand);
		PageVo<Brand> vo = brandService.select(brand, page, size);
		return ResponseEntity.ok(vo);
	}

	@AdminToken
	@CheckFormRepeat
	@PostMapping(value = "save", name = "保存品牌")
	@ResponseBody
	public ResponseEntity<Brand> save(Brand brand) {
		return ResponseEntity.ok(brandService.saveOrUpdate(brand));
	}

	@AdminToken
	@CheckFormRepeat
	@PostMapping(value = "status", name = "品牌上下架")
	@ResponseBody
	public ResponseEntity<BaseVo> status(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(brandService.status(id));
	}

	@AdminToken
	@CheckFormRepeat
	@DeleteMapping(value = "delete", name = "删除品牌")
	@ResponseBody
	public ResponseEntity<BaseVo> delete(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(brandService.delete(id));
	}

	@GetMapping(value = "selectById", name = "查看品牌信息")
	@ResponseBody
	public ResponseEntity<Brand> selectById(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(brandService.selectById(id));
	}
}